package so.sao.shop.supplier.web.account;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import so.sao.shop.supplier.domain.User;
import so.sao.shop.supplier.domain.account.AfterSetting;
import so.sao.shop.supplier.pojo.Result;
import so.sao.shop.supplier.service.account.AfterSettingService;
import so.sao.shop.supplier.util.JwtTokenUtil;

import javax.validation.Valid;
/**
 * <p>Version: supplier V1.2.0 </p>
 * <p>Title: AfterSetting</p>
 * <p>Description: 供应商售后设置</p>
 *
 * @author: cris
 * @Date: Created in 2017/11/22 10:05
 */
@RestController
@RequestMapping(value = "/afterSetting")
public class AfterSettingController {

    @Autowired
    private AfterSettingService afterSettingService;

    /**
     * 供应商售后设置添加
     * @param afterSetting
     * @return
     */
    @PostMapping(value = "/save")
    public Result<AfterSetting> save(@RequestBody @Valid AfterSetting afterSetting) {
        Assert.notNull(afterSetting,"保存的数据不能为空!");
        User user = JwtTokenUtil.getCurrentUser();
        afterSetting.setUserId(user.getId());
        afterSetting.setParentId(user.getParentId());
        return afterSettingService.save(afterSetting);
    }

    /**
     * 根据用户id查询售后设置
     * @return 返回售后设置
     */
    @GetMapping("/get")
    public Result<AfterSetting> get(){
        User user = JwtTokenUtil.getCurrentUser();
        return afterSettingService.get(user.getId(),user.getParentId());
    }

    /**
     * 根据用户id- accountId : 264 - 查询售后设置
     * @return 返回售后设置
     */
    @GetMapping("/getParentId/{accountId}")
    public AfterSetting getAfterSetting( @PathVariable Long accountId ){
        return afterSettingService.getAfterSetting( accountId );
    }


}
